import React from 'react';
import Button from '@mui/material/Button';

const ActionButtonCell = ({ onButtonClick, buttonLabel, ...params }) => {
  const onClick = () => {
    if (onButtonClick) {
      onButtonClick(params);
    }
  };

  // 阻止事件冒泡
  const stopPropagation = (event) => {
    event.stopPropagation();
  };

  // 添加键盘事件处理程序
  const handleKeyDown = (event) => {
    stopPropagation(event);
    if (event.key === 'Enter' || event.key === ' ') {
      onClick();
    }
  };
  return (
    <div onClick={stopPropagation} role="button" tabIndex={0} onKeyDown={handleKeyDown}>
      {' '}
      {/* 添加这个div来阻止冒泡 */}
      <Button color="primary" variant="contained" onClick={onClick}>
        {buttonLabel || '编辑'} {/* 使用传入的标签或默认为 "编辑" */}
      </Button>
    </div>
  );
};

export default ActionButtonCell;
